<style>
    .num{
        display: none;
        margin-left:100px;
    }
    .guage{
        display: none;
    }
</style>
<div class="content">
    <div class="header">
        <h1 class="page-title">修改题目</h1>
    </div>
    <ul class="breadcrumb">
        <!--<li><a href="index.html">Home</a> <span class="divider">/</span></li>-->
        <!--<li class="active">发布文章</li>-->
    </ul>
    
    <div class="container-fluid">
        <div class="row-fluid">

            <div class="btn-toolbar">
                <button class="btn btn-primary" onClick="location='<?php echo url('Admin/Index/topic_list'); ?>'"><i class="icon-list"></i> 题目列表</button>
                <div class="btn-group">
                </div>
            </div>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form action="" method="post">
                            <input type="hidden" name="top_id" value="<?php echo $top_info['top_id']; ?>">
                            <label>题目标题</label>
                            <input type="text" name="top_title" value="<?php echo $top_info['top_title']; ?>" class="input-xxlarge">
                            <label>所属问卷</label>
                            <select name="top_questionnaireid"  class="top_questionnaireid input-xxlarge">
                                <?php foreach( $que_list as $key => $val ){ ?>
                                <option value="<?php echo $val['qu_id']; ?>" <?php echo $top_info['top_questionnaireid'] == $val['qu_id'] ? 'selected' : '' ; ?>><?php echo $val['qu_title']; ?></option>
                                <?php } ?>
                            </select>
                            <label>所属大维度</label>
                            <select name="top_dimension"  class="dimension input-xxlarge">
                                <?php foreach( $dim_list as $key => $val ){ ?>
                                <option <?php if($top_info['top_dimension']==$val['dim_id']){ echo 'selected'; } ?> value="<?php echo $val['dim_id']; ?>"><?php echo $val['dim_name']; ?></option>
                                <?php } ?>
                            </select>
                            <label>所属小维度</label>
                            <select name="top_second_dimension"  class="second_dimension input-xxlarge">
                                <?php foreach( $dim_second_list as $key => $val ){ ?>
                                <option <?php if($top_info['top_second_dimension']==$val['dim_id']){ echo 'selected'; } ?> value="<?php echo $val['dim_id']; ?>"><?php echo $val['dim_name']; ?></option>
                                <?php } ?>
                            </select>
                            <label>所属部份</label>
                            <input type="number" name="top_section" value="<?php echo $top_info['top_section']; ?>" class="input-xxlarge">
                            <label>题目类型</label>
                            <select name="top_type" class="input-xxlarge top_type">
                                <option value="1" <?php echo $top_info['top_type'] == 1 ? 'selected' : '' ; ?>>单选</option>
                                <option value="2" <?php echo $top_info['top_type'] == 2 ? 'selected' : '' ; ?>>多选</option>
                                <option value="3" <?php echo $top_info['top_type'] == 3 ? 'selected' : '' ; ?>>填空</option>
                                <option value="4" <?php echo $top_info['top_type'] == 4 ? 'selected' : '' ; ?>>量表</option>
                                <option value="5" <?php echo $top_info['top_type'] == 5 ? 'selected' : '' ; ?>>跳转</option>
                            </select>
                            <!--单选题&多选题-->
                            <section class="option"   style="margin-left:100px;<?php if( $top_info['top_type'] !=1 && $top_info['top_type'] != 2 ) { echo 'display:none;';   } ?>">
                                <?php if( $top_info['top_type'] !=1 && $top_info['top_type'] != 2 ) { ?>
                                <label for="">选项1描述</label>
                                <input type="text" name="option[]">
                                <input type="number" placeholder="选项分数"  name="option_grade[]">
                                <label for="">选项2描述</label>
                                <input type="text" name="option[]">
                                <input type="number" placeholder="选项分数"  name="option_grade[]">
                                <label for="">选项3描述</label>
                                <input type="text" name="option[]">
                                <input type="number" placeholder="选项分数"  name="option_grade[]">
                                <label for="">选项4描述</label>
                                <input type="text" name="option[]">
                                <input type="number" placeholder="选项分数"  name="option_grade[]">
                                <?php } else { ?>
                                    <?php foreach ( $top_info['option'] as $key => $val ) {  ?>
                                        <label for="">选项<?php echo $key+1; ?>描述</label>
                                        <input type="text" value="<?php echo $val['opt_desc']; ?>" name="option[]">
                                        <input type="number" name="option_grade[]" value="<?php echo $val['opt_grade']; ?>">
                                    <?php } ?>
                                <?php } ?>
                            </section>
                            <!--跳转题-->
                            <section class="guage" style="margin-left:100px;<?php if( $top_info['top_type'] == 5 ) { echo 'display:block;'; } ?>" >

                                <?php if( $top_info['top_type'] !=5) { ?>
                                    <label for="">选项1描述</label>
                                    <input type="text" name="option_guage[]">
                                    <input type="number" name="guage_id[]" placeholder="跳转的id">
                                    <label for="">选项2描述</label>
                                    <input type="text" name="option_guage[]">
                                    <input type="number" name="guage_id[]" placeholder="跳转的id">
                                    <label for="">选项3描述</label>
                                    <input type="text" name="option_guage[]">
                                    <input type="number" name="guage_id[]" placeholder="跳转的id">
                                    <label for="">选项4描述</label>
                                    <input type="text" name="option_guage[]">
                                    <input type="number" name="guage_id[]" placeholder="跳转的id">
                                <?php } else { ?>
                                    <?php foreach ( $top_info['option'] as $key => $val ) {  ?>
                                        <label for="">选项<?php echo $key+1; ?>描述</label>
                                        <input type="text" name="option_guage[]" value="<?php echo $val['opt_desc']; ?>">
                                        <input type="number" name="guage_id[]" value="<?php echo $val['opt_guageid']; ?>" placeholder="跳转的id">
                                    <?php } ?>
                                <?php } ?>
                            </section>
                            <!--量表题-->
                            <section class="num" style="<?php if( $top_info['top_type'] == 4 ) { echo 'display:block;'; } ?>"  >
                                <input style="width:100px;" type="text" value="<?php echo $top_info['top_left_text']; ?>" class="input-xxlarge" placeholder="左边文字描述" name="top_left_text"> - <input style="width:100px;" placeholder="右边文字描述" type="text" class="input-xxlarge" name="top_right_text" value="<?php echo $top_info['top_right_text']; ?>">
                                <br>
                                <input style="width:100px;" type="number" value="<?php echo $top_info['top_minnumber']; ?>" class="input-xxlarge" placeholder="最小数值" name="top_minnumber"> - <input style="width:100px;" placeholder="最大数值" value="<?php echo $top_info['top_maxnumber']; ?>" type="number" class="input-xxlarge" name="top_maxnumber">
                                <br>
                                <input style="width:100px;" type="number" class="input-xxlarge" placeholder="得分间隔" value="<?php echo $top_info['top_interval']; ?>" name="top_interval">
                                <br>
                                <input type="checkbox" <?php if( $top_info['top_reverse'] == 1 ) { echo 'checked'; } ?> name="top_reverse" value="1" > 逆向得分
                            </section>
                            <div class="btn btn-primary add_option" style="margin-left:100px;<?php if( $top_info['top_type'] !=1 && $top_info['top_type'] != 2 ) { echo 'display:none;'; } ?>">增加新选项</div>
                            <div class="btn btn-primary add_guage" style="margin-left:100px;<?php if( $top_info['top_type'] !=5 ) { echo 'display:none;'; } ?>">增加新选项</div>
                            <!--<label>题目分数</label>-->
                            <!--<input type="number"  name="top_grade" value="<?php echo $top_info['top_grade']; ?>" class="input-xxlarge">-->
                            <label>题目排序(从大排到小)</label>
                            <input type="text" value="<?php echo $top_info['top_order']; ?>" name="top_order" value="" class="input-xxlarge">
                            <label>是否启用</label>
                            <input type="radio" <?php echo $top_info['top_status'] == 1 ? 'checked' : '' ; ?> name="top_status" value="1" class="input-xxlarge">是
                            <input type="radio" <?php echo $top_info['top_status'] == 2 ? 'checked' : '' ; ?> name="top_status" value="2" class="input-xxlarge">否
                            <label></label>
                            <input class="btn btn-primary" type="submit" value="提交" />
                        </form>
                    </div>
                </div>
            </div>
            <script>
                $('.top_type').change(function (){

                    if( $(this).val() == 1 || $(this).val() == 2 )
                    {

                        $('.option').show();
                        $('.add_option').show();
                        $('.num').hide();
                        $('.add_guage').hide();

                    } else if( $(this).val() == 4 ) {
                        $('.num').show()
                        $('.option').hide();
                        $('.add_option').hide();
                        $('.add_guage').hide();

                    } else if( $(this).val() == 5 ){

                        $('.guage').show()
                        $('.num').hide()
                        $('.option').hide();
                        $('.add_option').hide();
                        $('.add_guage').hide();

                    } else {
                        $('.num').hide();
                        $('.option').hide();
                        $('.add_option').hide();
                        $('.add_guage').hide();

                    }

                })
                var i = 5;
                $('.add_option').click(function (){
                    var str = '<label for="">选项'+i+'描述</label><input type="text" name="option[]"> <input type="number" placeholder="选项分数" name="option_grade[]">'
                    $('.option').append(str);
                    i++;
                })

                //添加跳转
                var gi = 5;
                $('.add_guage').click(function (){
                    var str = '<label for="">选项'+gi+'描述</label><input type="text" name="option_guage[]"> <input type="number" name="guage_id[]" placeholder="跳转的id">">'
                    $('.guage').append(str);
                    gi++;
                })

                $('.dimension').change(function (){
                    var str = ''
                    var dim_id = $(this).val()
                    //根据查出第一个大维度所属的小维度
                    url = '<?php echo url("Admin/Index/que_dim_second_list"); ?>?dim_id=' + dim_id
                    var data = {}
                    $.get(url,data,function (ev){
                        var str_second = ''
                        for(var i in ev){
                            if( i == 0 ){
                                str_second = "<option value='"+ ev[i].dim_id +"'>"+ ev[i].dim_name +"</option>"
                            } else {
                                str_second += "<option value='"+ ev[i].dim_id +"'>"+ ev[i].dim_name +"</option>"
                            }
                        }
                        if(str_second == ''){
                            str_second = '<option value="0">该大维度没有小维度</option>'
                        }
                        $('.second_dimension').html(str_second)
                        str_second = ""
                    },'json')

                })
            </script>
            <script>
                //获取该问卷所属的维度
                function wd_list(qu_id) {
                    var url = '<?php echo url("Admin/Index/que_dim_list"); ?>?qu_id=' + qu_id
                    var data = {}

                    $.get(url,data,function (e){
                        var str = ''
                        var dim_id = e[0].dim_id
                        //根据查出第一个大维度所属的小维度
                        url = '<?php echo url("Admin/Index/que_dim_second_list"); ?>?dim_id=' + dim_id
                        $.get(url,data,function (ev){
                            var str_second = ''
                            for(var i in ev){
                                if( i == 0 ){

                                    str_second = "<option value='"+ ev[i].dim_id +"'>"+ ev[i].dim_name +"</option>"
                                } else {
                                    str_second += "<option value='"+ ev[i].dim_id +"'>"+ ev[i].dim_name +"</option>"
                                }
                            }
                            if(str_second == ''){
                                str_second = '<option value="0">该大维度没有小维度</option>'
                            }
                            $('.second_dimension').html(str_second)
                            str_second = ""
                        },'json')
                        for(var i in e){
                            if( i == 0 ){
                                str = "<option value='"+ e[i].dim_id +"'>"+ e[i].dim_name +"</option>"
                            } else {
                                str += "<option value='"+ e[i].dim_id +"'>"+ e[i].dim_name +"</option>"
                            }
                        }

                        if(str == ''){
                            str = '<option value="0">该问卷没有标签</option>'
                        }

                        $('.dimension').html(str)
                        str = ""
                    },"json")
                }

                //问卷修改时，修改可选维度
                $('.top_questionnaireid').change(function (){
                    var qu_id = $(this).val()
                    wd_list(qu_id)
                })

            </script>
            <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                </div>
                <div class="modal-body">

                    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
                </div>